{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "f7632a09",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "65c7c923",
   "metadata": {},
   "outputs": [],
   "source": [
    "### 2.准备好API的接口身份\n",
    "API_Key = \"4udXjI9wvOnmb6uKVqr7gS0iwvSQcmc6\"\n",
    "API_Secret = \"FtFY8-LLw7rHqVd6NEsUviJ7PJE5ASJg\"\n",
    "\n",
    "### 3.准备base URL (face detect)\n",
    "\n",
    "base_url =\"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "\n",
    "### 4. 请求方法:POST\n",
    "\n",
    "\n",
    "### 5. 准备请求参数：payload\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret,\n",
    "    \"image_url\":\"https://img0.baidu.com/it/u=2164690002,4129730642&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=750\",\n",
    "    \"return_landmark\":1,\n",
    "    \"return_attributes\":'gender,age,smiling'\n",
    "}\n",
    "\n",
    "### 6. 请求数据\n",
    "\n",
    "r = requests.post(base_url,payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "115f8e02",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "05c36c7e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"request_id\":\"1647347450,1a3d34ab-66ec-46b0-b9de-42fc2515b5f9\",\"time_used\":272,\"faces\":[{\"face_token\":\"db9990e002001371b2010f31cd47b7a1\",\"face_rectangle\":{\"top\":258,\"left\":128,\"width\":283,\"height\":283},\"landmark\":{\"contour_chin\":{\"x\":279,\"y\":526},\"contour_left1\":{\"x\":123,\"y\":310},\"contour_left2\":{\"x\":127,\"y\":342},\"contour_left3\":{\"x\":134,\"y\":373},\"contour_left4\":{\"x\":142,\"y\":403},\"contour_left5\":{\"x\":152,\"y\":434},\"contour_left6\":{\"x\":167,\"y\":462},\"contour_left7\":{\"x\":187,\"y\":487},\"contour_left8\":{\"x\":213,\"y\":507},\"contour_left9\":{\"x\":243,\"y\":522},\"contour_right1\":{\"x\":406,\"y\":303},\"contour_right2\":{\"x\":404,\"y\":333},\"contour_right3\":{\"x\":399,\"y\":363},\"contour_right4\":{\"x\":392,\"y\":393},\"contour_right5\":{\"x\":384,\"y\":422},\"contour_right6\":{\"x\":373,\"y\":450},\"contour_right7\":{\"x\":356,\"y\":475},\"contour_right8\":{\"x\":336,\"y\":497},\"contour_right9\":{\"x\":312,\"y\":516},\"left_eye_bottom\":{\"x\":200,\"y\":320},\"left_eye_center\":{\"x\":202,\"y\":308},\"left_eye_left_corner\":{\"x\":173,\"y\":306},\"left_eye_lower_left_quarter\":{\"x\":184,\"y\":316},\"left_eye_lower_right_quarter\":{\"x\":217,\"y\":317},\"left_eye_pupil\":{\"x\":200,\"y\":305},\"left_eye_right_corner\":{\"x\":232,\"y\":312},\"left_eye_top\":{\"x\":203,\"y\":294},\"left_eye_upper_left_quarter\":{\"x\":186,\"y\":297},\"left_eye_upper_right_quarter\":{\"x\":219,\"y\":299},\"left_eyebrow_left_corner\":{\"x\":147,\"y\":294},\"left_eyebrow_lower_left_quarter\":{\"x\":169,\"y\":293},\"left_eyebrow_lower_middle\":{\"x\":192,\"y\":292},\"left_eyebrow_lower_right_quarter\":{\"x\":214,\"y\":295},\"left_eyebrow_right_corner\":{\"x\":237,\"y\":297},\"left_eyebrow_upper_left_quarter\":{\"x\":167,\"y\":280},\"left_eyebrow_upper_middle\":{\"x\":192,\"y\":277},\"left_eyebrow_upper_right_quarter\":{\"x\":217,\"y\":282},\"mouth_left_corner\":{\"x\":219,\"y\":446},\"mouth_lower_lip_bottom\":{\"x\":275,\"y\":467},\"mouth_lower_lip_left_contour1\":{\"x\":248,\"y\":449},\"mouth_lower_lip_left_contour2\":{\"x\":236,\"y\":456},\"mouth_lower_lip_left_contour3\":{\"x\":253,\"y\":464},\"mouth_lower_lip_right_contour1\":{\"x\":301,\"y\":448},\"mouth_lower_lip_right_contour2\":{\"x\":314,\"y\":455},\"mouth_lower_lip_right_contour3\":{\"x\":297,\"y\":464},\"mouth_lower_lip_top\":{\"x\":274,\"y\":450},\"mouth_right_corner\":{\"x\":329,\"y\":444},\"mouth_upper_lip_bottom\":{\"x\":274,\"y\":451},\"mouth_upper_lip_left_contour1\":{\"x\":262,\"y\":440},\"mouth_upper_lip_left_contour2\":{\"x\":241,\"y\":444},\"mouth_upper_lip_left_contour3\":{\"x\":247,\"y\":450},\"mouth_upper_lip_right_contour1\":{\"x\":286,\"y\":440},\"mouth_upper_lip_right_contour2\":{\"x\":307,\"y\":442},\"mouth_upper_lip_right_contour3\":{\"x\":301,\"y\":449},\"mouth_upper_lip_top\":{\"x\":274,\"y\":443},\"nose_contour_left1\":{\"x\":249,\"y\":313},\"nose_contour_left2\":{\"x\":244,\"y\":375},\"nose_contour_left3\":{\"x\":255,\"y\":407},\"nose_contour_lower_middle\":{\"x\":275,\"y\":415},\"nose_contour_right1\":{\"x\":291,\"y\":311},\"nose_contour_right2\":{\"x\":301,\"y\":372},\"nose_contour_right3\":{\"x\":294,\"y\":405},\"nose_left\":{\"x\":239,\"y\":396},\"nose_right\":{\"x\":308,\"y\":392},\"nose_tip\":{\"x\":277,\"y\":400},\"right_eye_bottom\":{\"x\":342,\"y\":315},\"right_eye_center\":{\"x\":339,\"y\":303},\"right_eye_left_corner\":{\"x\":307,\"y\":311},\"right_eye_lower_left_quarter\":{\"x\":323,\"y\":314},\"right_eye_lower_right_quarter\":{\"x\":358,\"y\":310},\"right_eye_pupil\":{\"x\":337,\"y\":298},\"right_eye_right_corner\":{\"x\":368,\"y\":300},\"right_eye_top\":{\"x\":338,\"y\":287},\"right_eye_upper_left_quarter\":{\"x\":320,\"y\":295},\"right_eye_upper_right_quarter\":{\"x\":355,\"y\":290},\"right_eyebrow_left_corner\":{\"x\":301,\"y\":299},\"right_eyebrow_lower_left_quarter\":{\"x\":323,\"y\":293},\"right_eyebrow_lower_middle\":{\"x\":344,\"y\":287},\"right_eyebrow_lower_right_quarter\":{\"x\":363,\"y\":285},\"right_eyebrow_right_corner\":{\"x\":381,\"y\":285},\"right_eyebrow_upper_left_quarter\":{\"x\":321,\"y\":283},\"right_eyebrow_upper_middle\":{\"x\":342,\"y\":273},\"right_eyebrow_upper_right_quarter\":{\"x\":363,\"y\":272}},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":25},\"smile\":{\"value\":0.249,\"threshold\":50.000}}}],\"image_id\":\"U5CpILjjZXWZQH86bdF31Q==\",\"face_num\":1}\\n'"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "32871004",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647347450,1a3d34ab-66ec-46b0-b9de-42fc2515b5f9',\n",
       " 'time_used': 272,\n",
       " 'faces': [{'face_token': 'db9990e002001371b2010f31cd47b7a1',\n",
       "   'face_rectangle': {'top': 258, 'left': 128, 'width': 283, 'height': 283},\n",
       "   'landmark': {'contour_chin': {'x': 279, 'y': 526},\n",
       "    'contour_left1': {'x': 123, 'y': 310},\n",
       "    'contour_left2': {'x': 127, 'y': 342},\n",
       "    'contour_left3': {'x': 134, 'y': 373},\n",
       "    'contour_left4': {'x': 142, 'y': 403},\n",
       "    'contour_left5': {'x': 152, 'y': 434},\n",
       "    'contour_left6': {'x': 167, 'y': 462},\n",
       "    'contour_left7': {'x': 187, 'y': 487},\n",
       "    'contour_left8': {'x': 213, 'y': 507},\n",
       "    'contour_left9': {'x': 243, 'y': 522},\n",
       "    'contour_right1': {'x': 406, 'y': 303},\n",
       "    'contour_right2': {'x': 404, 'y': 333},\n",
       "    'contour_right3': {'x': 399, 'y': 363},\n",
       "    'contour_right4': {'x': 392, 'y': 393},\n",
       "    'contour_right5': {'x': 384, 'y': 422},\n",
       "    'contour_right6': {'x': 373, 'y': 450},\n",
       "    'contour_right7': {'x': 356, 'y': 475},\n",
       "    'contour_right8': {'x': 336, 'y': 497},\n",
       "    'contour_right9': {'x': 312, 'y': 516},\n",
       "    'left_eye_bottom': {'x': 200, 'y': 320},\n",
       "    'left_eye_center': {'x': 202, 'y': 308},\n",
       "    'left_eye_left_corner': {'x': 173, 'y': 306},\n",
       "    'left_eye_lower_left_quarter': {'x': 184, 'y': 316},\n",
       "    'left_eye_lower_right_quarter': {'x': 217, 'y': 317},\n",
       "    'left_eye_pupil': {'x': 200, 'y': 305},\n",
       "    'left_eye_right_corner': {'x': 232, 'y': 312},\n",
       "    'left_eye_top': {'x': 203, 'y': 294},\n",
       "    'left_eye_upper_left_quarter': {'x': 186, 'y': 297},\n",
       "    'left_eye_upper_right_quarter': {'x': 219, 'y': 299},\n",
       "    'left_eyebrow_left_corner': {'x': 147, 'y': 294},\n",
       "    'left_eyebrow_lower_left_quarter': {'x': 169, 'y': 293},\n",
       "    'left_eyebrow_lower_middle': {'x': 192, 'y': 292},\n",
       "    'left_eyebrow_lower_right_quarter': {'x': 214, 'y': 295},\n",
       "    'left_eyebrow_right_corner': {'x': 237, 'y': 297},\n",
       "    'left_eyebrow_upper_left_quarter': {'x': 167, 'y': 280},\n",
       "    'left_eyebrow_upper_middle': {'x': 192, 'y': 277},\n",
       "    'left_eyebrow_upper_right_quarter': {'x': 217, 'y': 282},\n",
       "    'mouth_left_corner': {'x': 219, 'y': 446},\n",
       "    'mouth_lower_lip_bottom': {'x': 275, 'y': 467},\n",
       "    'mouth_lower_lip_left_contour1': {'x': 248, 'y': 449},\n",
       "    'mouth_lower_lip_left_contour2': {'x': 236, 'y': 456},\n",
       "    'mouth_lower_lip_left_contour3': {'x': 253, 'y': 464},\n",
       "    'mouth_lower_lip_right_contour1': {'x': 301, 'y': 448},\n",
       "    'mouth_lower_lip_right_contour2': {'x': 314, 'y': 455},\n",
       "    'mouth_lower_lip_right_contour3': {'x': 297, 'y': 464},\n",
       "    'mouth_lower_lip_top': {'x': 274, 'y': 450},\n",
       "    'mouth_right_corner': {'x': 329, 'y': 444},\n",
       "    'mouth_upper_lip_bottom': {'x': 274, 'y': 451},\n",
       "    'mouth_upper_lip_left_contour1': {'x': 262, 'y': 440},\n",
       "    'mouth_upper_lip_left_contour2': {'x': 241, 'y': 444},\n",
       "    'mouth_upper_lip_left_contour3': {'x': 247, 'y': 450},\n",
       "    'mouth_upper_lip_right_contour1': {'x': 286, 'y': 440},\n",
       "    'mouth_upper_lip_right_contour2': {'x': 307, 'y': 442},\n",
       "    'mouth_upper_lip_right_contour3': {'x': 301, 'y': 449},\n",
       "    'mouth_upper_lip_top': {'x': 274, 'y': 443},\n",
       "    'nose_contour_left1': {'x': 249, 'y': 313},\n",
       "    'nose_contour_left2': {'x': 244, 'y': 375},\n",
       "    'nose_contour_left3': {'x': 255, 'y': 407},\n",
       "    'nose_contour_lower_middle': {'x': 275, 'y': 415},\n",
       "    'nose_contour_right1': {'x': 291, 'y': 311},\n",
       "    'nose_contour_right2': {'x': 301, 'y': 372},\n",
       "    'nose_contour_right3': {'x': 294, 'y': 405},\n",
       "    'nose_left': {'x': 239, 'y': 396},\n",
       "    'nose_right': {'x': 308, 'y': 392},\n",
       "    'nose_tip': {'x': 277, 'y': 400},\n",
       "    'right_eye_bottom': {'x': 342, 'y': 315},\n",
       "    'right_eye_center': {'x': 339, 'y': 303},\n",
       "    'right_eye_left_corner': {'x': 307, 'y': 311},\n",
       "    'right_eye_lower_left_quarter': {'x': 323, 'y': 314},\n",
       "    'right_eye_lower_right_quarter': {'x': 358, 'y': 310},\n",
       "    'right_eye_pupil': {'x': 337, 'y': 298},\n",
       "    'right_eye_right_corner': {'x': 368, 'y': 300},\n",
       "    'right_eye_top': {'x': 338, 'y': 287},\n",
       "    'right_eye_upper_left_quarter': {'x': 320, 'y': 295},\n",
       "    'right_eye_upper_right_quarter': {'x': 355, 'y': 290},\n",
       "    'right_eyebrow_left_corner': {'x': 301, 'y': 299},\n",
       "    'right_eyebrow_lower_left_quarter': {'x': 323, 'y': 293},\n",
       "    'right_eyebrow_lower_middle': {'x': 344, 'y': 287},\n",
       "    'right_eyebrow_lower_right_quarter': {'x': 363, 'y': 285},\n",
       "    'right_eyebrow_right_corner': {'x': 381, 'y': 285},\n",
       "    'right_eyebrow_upper_left_quarter': {'x': 321, 'y': 283},\n",
       "    'right_eyebrow_upper_middle': {'x': 342, 'y': 273},\n",
       "    'right_eyebrow_upper_right_quarter': {'x': 363, 'y': 272}},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 25},\n",
       "    'smile': {'value': 0.249, 'threshold': 50.0}}}],\n",
       " 'image_id': 'U5CpILjjZXWZQH86bdF31Q==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "62661049",
   "metadata": {},
   "outputs": [],
   "source": [
    "### 2.准备好API的接口身份\n",
    "API_Key = \"4udXjI9wvOnmb6uKVqr7gS0iwvSQcmc6\"\n",
    "API_Secret = \"FtFY8-LLw7rHqVd6NEsUviJ7PJE5ASJg\"\n",
    "\n",
    "### 3.准备base URL (face detect)\n",
    "\n",
    "base_url =\"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "\n",
    "### 4. 请求方法:POST\n",
    "\n",
    "\n",
    "### 5. 准备请求参数：payload\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret,\n",
    "    \"image_url\":\"https://img2.baidu.com/it/u=327363434,4196540052&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=375\",\n",
    "\n",
    "}\n",
    "\n",
    "### 6. 请求数据\n",
    "\n",
    "r = requests.post(base_url,payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "fd4f9409",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "e85102df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"request_id\":\"1647345508,4de8da45-4101-4f61-9c91-ba3dd7bd9aff\",\"time_used\":70,\"faces\":[{\"face_token\":\"89a9f90f3aa5b3aab636fc9369288b99\",\"face_rectangle\":{\"top\":98,\"left\":143,\"width\":215,\"height\":215}}],\"image_id\":\"DyVi9H0vvgqD6UJVA8ECjg==\",\"face_num\":1}\\n'"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "63bbde83",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647345508,4de8da45-4101-4f61-9c91-ba3dd7bd9aff',\n",
       " 'time_used': 70,\n",
       " 'faces': [{'face_token': '89a9f90f3aa5b3aab636fc9369288b99',\n",
       "   'face_rectangle': {'top': 98, 'left': 143, 'width': 215, 'height': 215}}],\n",
       " 'image_id': 'DyVi9H0vvgqD6UJVA8ECjg==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "23db9ffc",
   "metadata": {},
   "outputs": [],
   "source": [
    "face_detect = r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "5407bea7",
   "metadata": {},
   "outputs": [],
   "source": [
    "face_tokens = face_detect['faces'][0]['face_token']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "ddf13464",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'89a9f90f3aa5b3aab636fc9369288b99'"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_tokens"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "520f4913",
   "metadata": {},
   "source": [
    "# 人脸分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "bd201813",
   "metadata": {},
   "outputs": [],
   "source": [
    "### 2.准备好API的接口身份\n",
    "API_Key = \"4udXjI9wvOnmb6uKVqr7gS0iwvSQcmc6\"\n",
    "API_Secret = \"FtFY8-LLw7rHqVd6NEsUviJ7PJE5ASJg\"\n",
    "\n",
    "### 3.准备base URL (face detect)\n",
    "\n",
    "base_url =\"https://api-cn.faceplusplus.com/facepp/v3/face/analyze\"\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret,\n",
    "    \"face_tokens\":'b757833936c9936998954ffc78a77862',\n",
    "    \"return_attributes\":'gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,beauty,mouthstatus,eyegaze,skinstatus',\n",
    "    \"beauty_score_min\":0,\n",
    "    \"beauty_score_max\":100\n",
    "\n",
    "}\n",
    "r_analyze = requests.post(url = base_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "0bc9498c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "9711f0e6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"request_id\":\"1647345508,4de8da45-4101-4f61-9c91-ba3dd7bd9aff\",\"time_used\":70,\"faces\":[{\"face_token\":\"89a9f90f3aa5b3aab636fc9369288b99\",\"face_rectangle\":{\"top\":98,\"left\":143,\"width\":215,\"height\":215}}],\"image_id\":\"DyVi9H0vvgqD6UJVA8ECjg==\",\"face_num\":1}\\n'"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "5613cce1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647345508,4de8da45-4101-4f61-9c91-ba3dd7bd9aff',\n",
       " 'time_used': 70,\n",
       " 'faces': [{'face_token': '89a9f90f3aa5b3aab636fc9369288b99',\n",
       "   'face_rectangle': {'top': 98, 'left': 143, 'width': 215, 'height': 215}}],\n",
       " 'image_id': 'DyVi9H0vvgqD6UJVA8ECjg==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "6e624af5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "8a37092c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_token</th>\n",
       "      <th>face_rectangle.top</th>\n",
       "      <th>face_rectangle.left</th>\n",
       "      <th>face_rectangle.width</th>\n",
       "      <th>face_rectangle.height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>89a9f90f3aa5b3aab636fc9369288b99</td>\n",
       "      <td>98</td>\n",
       "      <td>143</td>\n",
       "      <td>215</td>\n",
       "      <td>215</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         face_token  face_rectangle.top  face_rectangle.left  \\\n",
       "0  89a9f90f3aa5b3aab636fc9369288b99                  98                  143   \n",
       "\n",
       "   face_rectangle.width  face_rectangle.height  \n",
       "0                   215                    215  "
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.json_normalize(r.json()[\"faces\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9fa519fa",
   "metadata": {},
   "source": [
    "# 人脸对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "ac4d50ae",
   "metadata": {},
   "outputs": [],
   "source": [
    "face01=\"db9990e002001371b2010f31cd47b7a1\"\n",
    "face02=\"89a9f90f3aa5b3aab636fc9369288b99\"\n",
    "### 2.准备好API的接口身份\n",
    "API_Key = \"4udXjI9wvOnmb6uKVqr7gS0iwvSQcmc6\"\n",
    "API_Secret = \"FtFY8-LLw7rHqVd6NEsUviJ7PJE5ASJg\"\n",
    "\n",
    "### 3.准备base URL (face detect)\n",
    "\n",
    "base_url =\"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret,\n",
    "    \"face_token1\":face01,\n",
    "    \"face_token2\":face02\n",
    "}\n",
    "r = requests.post(url = base_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "770c7b8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "2f935907",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"request_id\":\"1647347703,514129de-496b-433b-ac34-3d4b210193d4\",\"time_used\":321,\"confidence\":60.366,\"thresholds\":{\"1e-3\":62.327,\"1e-4\":69.101,\"1e-5\":73.975}}\\n'"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "374819b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647347703,514129de-496b-433b-ac34-3d4b210193d4',\n",
       " 'time_used': 321,\n",
       " 'confidence': 60.366,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-4': 69.101, '1e-5': 73.975}}"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1d84d99",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 准备工作\n",
    "import requests\n",
    "API_key = 'jRpCaZ34kqNYJ8Zppdc-yGGum_YkETov'\n",
    "API_sercret = 'Vr0PtRCw-ZFwYXTKVfi6aDNaSqlfunK3'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "794b9f2c",
   "metadata": {},
   "outputs": [],
   "source": [
    "def face_detect(API_key,API_sercret,image_path,landmark=None,attributes=None,face_rectangle=None,beauty_score_min=0,beauty_score_max=100):\n",
    "    \"\"\"该函数为调用face++ face_detect接口\"\"\"\n",
    "    base_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'\n",
    "    files = {'image_file': ('Liu_01.jpeg', open('Liu_01.jpeg', 'rb'), 'multipart/form-data')}\n",
    "    payload = {\n",
    "            'api_key':API_key,\n",
    "            'api_secret':API_sercret,\n",
    "            'image_url':image_url,\n",
    "            \"return_landmark\":landmark,\n",
    "            \"return_attributes\":attributes,\n",
    "            \"face_rectangle\":face_rectangle,\n",
    "            \"beauty_score_min\":beauty_score_min,\n",
    "            \"beauty_score_max\":beauty_score_max\n",
    "            \n",
    "            }\n",
    "    \n",
    "\n",
    "    r = requests.post(base_url, params = payload,files = files )\n",
    "    return r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "036d93c8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
